
//
//  ZPVisitorView.swift
//  ZPWeiBo01
//
//  Created by Nevermore on 16/9/2.
//  Copyright © 2016年 Nevermore. All rights reserved.
//

import UIKit
import SnapKit
class ZPVisitorView: UIView {

    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK: -供外界调用的方法
    func setupVisitorViewInfo(imageName:String?,title:String?){
        if let img = imageName,let tit = title{
            iconImageView.image = UIImage(named: img)
            
            messageLabel.text = tit
            
        }else{
            //代表首页
            setupAnim()
            
        }
        
        
    }
    //MARK:-设置动画
    
    func setupAnim(){
        
        let anim = CABasicAnimation(keyPath: "transform.rotation")
        anim.toValue = M_PI * 2
        
        anim.duration = 10
        
        anim.repeatCount = MAXFLOAT
        
        anim.removedOnCompletion = false
        
        CircleImageView.layer.addAnimation(anim, forKey: nil)
    }
    
    
    private func setupUI(){
        
        backgroundColor = RandomColor()
        addSubview(CircleImageView)
        addSubview(MaskImageView)
        addSubview(iconImageView)
        addSubview(messageLabel)
        addSubview(registButton)
        addSubview(loginButton)
        CircleImageView.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(self)
        }
        MaskImageView.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(self)
        }
        iconImageView.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(self)
        }
        messageLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(MaskImageView.snp_bottom).offset(16)
            make.height.equalTo(36)
            make.centerX.equalTo(self)
        }
        registButton.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(messageLabel)
            make.size.equalTo(CGSize(width: 100, height: 36))
            make.top.equalTo(messageLabel.snp_bottom).offset(16)
        }
        loginButton.snp_makeConstraints { (make) -> Void in
            make.trailing.equalTo(messageLabel)
            make.size.top.equalTo(registButton)
        }
    }
    
    private lazy var CircleImageView: UIImageView = UIImageView(imgName: "visitordiscover_feed_image_smallicon")
    private lazy var MaskImageView: UIImageView = UIImageView(imgName: "visitordiscover_feed_mask_smallicon")
    private lazy var iconImageView:UIImageView = UIImageView(imgName: "visitordiscover_feed_image_house")
    private lazy var messageLabel: UILabel = {
        let lab = UILabel()
        lab.textColor = AppThemeColor
        
        lab.font = UIFont.systemFontOfSize(15)
        
        lab.numberOfLines = 0
        lab.textAlignment = .Center
        lab.text = "关注一些人,回这里看看有什么惊喜,关注一些人,回这里看看有什么惊喜"
        lab.preferredMaxLayoutWidth = 240
        return lab
    }()
    private lazy var registButton: UIButton = {
        let button = UIButton()
        button.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
        button.setTitle("注册", forState: UIControlState.Normal)
        button.titleLabel?.font = UIFont.systemFontOfSize(16)
        button.setTitleColor(AppThemeColor, forState: UIControlState.Normal)
        return button
    }()
    private lazy var loginButton: UIButton = {
        let button = UIButton()
        button.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)
        button.setTitle("登录", forState: UIControlState.Normal)
        button.titleLabel?.font = UIFont.systemFontOfSize(16)
        button.setTitleColor(AppThemeColor, forState: UIControlState.Normal)
        return button
    }()
    
   // visitordiscover_feed_mask_smallicon
}
